package wpwork.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import wpwork.base.mapper.SuperMapper;
import wpwork.entity.UserGroupRelationEntity;

import java.util.List;
@Mapper
public interface UserGroupRelationMapper extends SuperMapper<UserGroupRelationEntity> {

    @Delete("DELETE FROM ksh_user_group_relation WHERE f_user_id = #{userId} AND f_group_id = #{groupId}")
    int deleteByUserIdAndGroupId(@Param("userId") String userId, @Param("groupId") Long groupId);

    @Delete("DELETE FROM ksh_user_group_relation WHERE f_group_id = #{groupId}")
    int deleteByGroupId(@Param("groupId") Long groupId);

    @Delete("DELETE FROM ksh_user_group_relation WHERE f_user_id = #{userId}")
    int deleteByUserId(@Param("userId") String userId);

    @Select("SELECT f_user_id FROM ksh_user_group_relation WHERE f_group_id = #{groupId}")
    List<String> selectUserIdsByGroupId(@Param("groupId") Long groupId);

    @Select("SELECT f_group_id FROM ksh_user_group_relation WHERE f_user_id = #{userId}")
    List<Long> selectGroupIdsByUserId(@Param("userId") String userId);

    @Select("SELECT * FROM ksh_user_group_relation WHERE f_group_id = #{groupId}")
    List<UserGroupRelationEntity> selectByGroupId(@Param("groupId") Long groupId);

    @Select("SELECT COUNT(*) FROM ksh_user_group_relation WHERE f_user_id = #{userId} AND f_group_id = #{groupId}")
    boolean existsByUserIdAndGroupId(@Param("userId") String userId, @Param("groupId") Long groupId);
}
